// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.randomizedWorld.randomizedDeadSurvivor;

import java.util.ArrayList;
import zombie.characters.IsoPlayer;
import zombie.core.Rand;
import zombie.iso.BuildingDef;
import zombie.iso.IsoGridSquare;
import zombie.iso.RoomDef;
import zombie.network.GameClient;
import zombie.network.GameServer;
import zombie.util.list.PZArrayUtil;

public final class RDSBandPractice extends RandomizedDeadSurvivorBase {
    private final ArrayList<String> instrumentsList = new ArrayList();

    public RDSBandPractice() {
        this.name = "Band Practice";
        this.setChance(10);
        this.setMaximumDays(60);
        this.instrumentsList.add("GuitarAcoustic");
        this.instrumentsList.add("GuitarElectricBlack");
        this.instrumentsList.add("GuitarElectricBlue");
        this.instrumentsList.add("GuitarElectricRed");
        this.instrumentsList.add("GuitarElectricBassBlue");
        this.instrumentsList.add("GuitarElectricBassBlack");
        this.instrumentsList.add("GuitarElectricBassRed");
    }

    @Override
    public void randomizeDeadSurvivor(BuildingDef def) {
        this.spawnItemsInContainers(def, "BandPractice", 90);
        RoomDef roomDef = this.getRoom(def, "garagestorage");
        if (roomDef == null) {
            roomDef = this.getRoom(def, "shed");
        }

        if (roomDef == null) {
            roomDef = this.getRoom(def, "garage");
        }

        this.addZombies(def, Rand.Next(2, 4), "Rocker", Integer.valueOf(20), roomDef);
        IsoGridSquare isoGridSquare = getRandomSpawnSquare(roomDef);
        if (isoGridSquare != null) {
            isoGridSquare.AddWorldInventoryItem(PZArrayUtil.pickRandom(this.instrumentsList), Rand.Next(0.0F, 0.5F), Rand.Next(0.0F, 0.5F), 0.0F);
            if (Rand.Next(4) == 0) {
                isoGridSquare.AddWorldInventoryItem(PZArrayUtil.pickRandom(this.instrumentsList), Rand.Next(0.0F, 0.5F), Rand.Next(0.0F, 0.5F), 0.0F);
            }

            if (Rand.Next(4) == 0) {
                isoGridSquare.AddWorldInventoryItem(PZArrayUtil.pickRandom(this.instrumentsList), Rand.Next(0.0F, 0.5F), Rand.Next(0.0F, 0.5F), 0.0F);
            }

            def.bAlarmed = false;
        }
    }

    @Override
    public boolean isValid(BuildingDef def, boolean force) {
        this.debugLine = "";
        if (GameClient.bClient) {
            return false;
        } else if (def.isAllExplored() && !force) {
            return false;
        } else {
            if (!force) {
                for (int int0 = 0; int0 < GameServer.Players.size(); int0++) {
                    IsoPlayer isoPlayer = (IsoPlayer)GameServer.Players.get(int0);
                    if (isoPlayer.getSquare() != null && isoPlayer.getSquare().getBuilding() != null && isoPlayer.getSquare().getBuilding().def == def) {
                        return false;
                    }
                }
            }

            boolean _boolean = false;

            for (int int1 = 0; int1 < def.rooms.size(); int1++) {
                RoomDef roomDef = (RoomDef)def.rooms.get(int1);
                if (("garagestorage".equals(roomDef.name) || "shed".equals(roomDef.name) || "garage".equals(roomDef.name)) && roomDef.area >= 9) {
                    _boolean = true;
                    break;
                }
            }

            if (!_boolean) {
                this.debugLine = "No shed/garage or is too small";
            }

            return _boolean;
        }
    }
}
